package com.zmovie.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmovie.framework.domain.Hall;
import com.zmovie.framework.service.HallService;
import com.zmovie.framework.mapper.HallMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author lenovo
* @description 针对表【hall】的数据库操作Service实现
* @createDate 2023-12-02 17:48:20
*/
@Service
public class HallServiceImpl extends ServiceImpl<HallMapper, Hall>
    implements HallService{
    @Autowired
    private HallMapper hallMapper;
    @Override
    public Page<Hall> pageHall(Integer pageNo, Integer pageSize, Hall hall) {
        Page<Hall> hallPage = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<Hall> wrapper = new LambdaQueryWrapper<>();
        //所属影院
        wrapper.eq(hall.getCinemaId() != null, Hall::getCinemaId, hall.getCinemaId());
        //影厅分类
        wrapper.eq(hall.getHallTypeId() != null, Hall::getHallTypeId, hall.getHallTypeId());
        //影厅状态
        wrapper.eq(hall.getHallState() != null, Hall::getHallState, hall.getHallState());
        wrapper.orderByAsc(Hall::getCinemaId).orderByAsc(Hall::getHallTypeId);
        return page(hallPage, wrapper);
    }

    @Override
    public boolean updateHallState(Hall hall) {
        if(hall.getId() == null || hall.getHallState() == null) return false;
        LambdaUpdateWrapper<Hall> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Hall::getId, hall.getId());
        wrapper.set(Hall::getHallState, hall.getHallState());
        return update(wrapper);
    }

    @Override
    public boolean updateHallSeat(Hall hall) {
        if(hall.getId() == null || hall.getSeatState() == null){
            return false;
        }
        LambdaUpdateWrapper<Hall> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Hall::getId, hall.getId());
        wrapper.set(Hall::getSeatState, hall.getSeatState());
        return update(wrapper);
    }

    @Override
    public List<Hall> listHallByCinemaId(Integer cinemaId) {
        if(cinemaId == null){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<Hall> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Hall::getCinemaId, cinemaId);
        wrapper.orderByAsc(Hall::getName);
        return list(wrapper);
    }

    @Override
    public List<String> listHallTypeNamesByCinemaId(Integer cinemaId) {
        return hallMapper.listHallTypeNamesByCinemaId(cinemaId);
    }
}




